package com.test.demo.service;

import com.test.demo.entity.UserBean;
import com.test.demo.event.UserRegisterEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    /**
     * 注入ApplicationContext用来发布事件
     */
    @Autowired
    ApplicationContext applicationContext;

    /**
     * 用户注册方法
     *
     * @param user
     */
    public void register(UserBean user) {
        //../省略其他逻辑

        //发布UserRegisterEvent事件
        //使用ApplicationContext对象的publishEvent发布事件
        applicationContext.publishEvent(new UserRegisterEvent(this, user));
    }
}